<script setup lang="ts">
import { ref } from 'vue'

/**
  v-for="(item, index) in arr"
 */

const list = ref(['西瓜', '苹果', '鸭梨', '榴莲'])

const goodsList = [
  { id: 1001, name: '西瓜' },
  { id: 1002, name: '苹果' },
  { id: 1003, name: '鸭梨' },
  { id: 1004, name: '榴莲' }
]

const person = {
  name: '张三',
  age: 18,
  gender: '男'
}

const intro = '今天天气很好'
</script>


<template>
  <div class="box">
    <!-- 遍历字符串 -->
    <ul>
      <li v-for="(item, index) in intro" :key="index">{{ item }}</li>
    </ul>
    <!-- 遍历数字 -->
    <ul>
      <li v-for="item in 5" :key="item">{{ item }}</li>
    </ul>
    <!-- 遍历对象 -->
    <ul>
      <li v-for="(value, key, index) in person" :key="index">键: {{ key }}, 值: {{ value }}</li>
    </ul>
    <!-- 遍历数组 -->
    <ul>
      <li v-for="(item, index) in list" :key="index">序号: {{ index + 1 }} ---- 名称: {{ item }}</li>
    </ul>

    <ul>
      <li v-for="item in list" :key="item">名称: {{ item }}</li>
    </ul>

    <ul>
      <li v-for="item in goodsList" :key="item.id">名称: {{ item.name }}</li>
    </ul>
  </div>
</template>

<style></style>
